﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GLY_XieTong;
using fuzhu;
using System.Data.SqlClient;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using RestSharp;
using XXX.Common;

namespace LVJU_XieTong
{
    public class LVJUXieTong
    {
        /// <summary>
        /// 对方web接口地址
        /// </summary>
        string  _url { get; set; }
        string  _token { get; set; }
        string  _cconstr { get; set; } 
        /// <summary>
        /// 绿驹业务同步
        /// </summary>
        /// <param name="CLX">同步类型</param>
        /// <param name="IID">同步id，如果是0，就全部同步</param>
        /// <param name="CCONSTR">中间库连接字符串</param>
        /// <returns></returns>
        public string HANDXieTong(string CLX, int IID, string CCONSTR)
        {
            string cErr = "";
            _cconstr = CCONSTR;
            _url = DbHelper.GetDbString(DbHelper2.ExecuteScalar("SELECT cvalue FROM zdy_inter_para WHERE lx=17 ", CCONSTR));
            _token = DbHelper.GetDbString(DbHelper2.ExecuteScalar("SELECT cvalue FROM zdy_inter_para WHERE lx=18 ", CCONSTR));
            switch (CLX)
            {
                case "存货档案":
                    cErr=PostInv();
                    break;
                case "客户档案":
                    cErr = PostCus();
                    break;
                case "销售参数":
                    cErr = PostSalePara();
                    break;
                case "销售订单":
                    cErr = PostSo();
                    break;

                case "all":
                    cErr ="读取存货："+ PostInv()+"\r\n";
                    cErr += "读取客户：" + PostCus() + "\r\n";
                    cErr += "读取销售参数：" + PostSalePara();
                    break;
                default:
                    break;
            }
            return cErr;
        }

        #region 写入中间表日志

//        private void WriteInterLog(int iSourceID, string cCode, string cTarCode, string cLx, string cInterLx, string cRe, string cConstr)
//        {
//            SqlParameter[] param = new SqlParameter[]{ 
//                new SqlParameter("@ccode",cCode),
//                new SqlParameter("@iSourceID",iSourceID),
//                new SqlParameter("@cTarCode",cTarCode),
//                 new SqlParameter("@cLx",cInterLx),
//                new SqlParameter("@cInterLx",cInterLx),
//                new SqlParameter("@cRe",cRe)                                         
//          };
//            string sql = string.Format(@"INSERT INTO ZDY_INTER_XIETONGLOG(ccode,ISOURCEID,CTARCODE,CLX,CINTERLX,DUPDATETIME,CREMARK)
//VALUES(@ccode,@iSourceID,@cTarCode,@cLx,@cInterLx,getdate(),@cRe)");
//            DbHelper2.ExecuteNonQuery(sql, param, CommandType.Text,cConstr);

//        }
        #endregion



        #region 存货档案推送
        public string PostInv()
        {
            try
            {
                //string url = string.Format("?token={0}&type={1}&features={2}", "yonyou", "erp", "productData");
                string url = string.Format("{0}/publicInterface.do?token={1}&type={2}&features={3}", _url, _token, "erp", "productData");
                //LogHelper.WriteLog(url);
                //url = "http://demo.startdream.vip/info/openInter/publicInterface.do?token=yonyou&type=erp&features=baseCust";
                var client = new RestClient(url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                IRestResponse response = client.Execute(request);
                //LoggerHelper loggerHelper = new LoggerHelper();
                //loggerHelper.Info("LVJUXieTong",  response.Content);
                //结果返回类
                //JsonConvert,将jason转换成类，返回成功，更新u8已上传状态
                FanHuiDatailINV obj = JsonConvert.DeserializeObject<FanHuiDatailINV>(response.Content);
                if (obj.success.ToLower() == "true")
                {
                    //写到数据表
                    //先清空再插入，然后更新存货档案
                    List<Inventory> lst = obj.list;
                    string sql = "truncate table zdy_lvju_inventory ";
                    DbHelper2.ExecuteNonQuery(sql, _cconstr);
                    for (int i = 0; i < lst.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@material_type",DbHelper.ToDbValue(lst[i].material_type)),
                 new SqlParameter("@material_spec",DbHelper.ToDbValue(lst[i].material_spec)),
                  new SqlParameter("@s_n",DbHelper.ToDbValue(lst[i].s_n)),
                   new SqlParameter("@unit_code",DbHelper.ToDbValue(lst[i].unit_code)),
                    new SqlParameter("@color_desc",DbHelper.ToDbValue(lst[i].color_desc)),
                     new SqlParameter("@material_name",DbHelper.ToDbValue(lst[i].material_name)),
                     new SqlParameter("@color_code",DbHelper.ToDbValue(lst[i].color_code)),
                     new SqlParameter("@material_code",DbHelper.ToDbValue(lst[i].material_code))
          };


                        sql = @"insert into zdy_lvju_inventory(material_type,material_spec,s_n,unit_code,color_desc,material_name," +
                            "color_code,material_code) values(@material_type,@material_spec,@s_n,@unit_code,@color_desc,@material_name," +
                            "@color_code,@material_code) ";
                        DbHelper2.ExecuteNonQuery(sql, param, _cconstr);

                    }
                    //执行存储，更新分类、计量单位
                    SqlParameter[] param2 = new SqlParameter[]{
                new SqlParameter("@error",SqlDbType.VarChar,1000) };
                    param2[0].Direction = ParameterDirection.Output;

                    DbHelper2.ExecuteNonQuery("zdy_lvju_sp_ImportInv", param2, CommandType.StoredProcedure,_cconstr);
                    string cError = param2[0].Value.ToString();
                    if (cError != "ok")
                    {
                        Exception ex = new Exception(cError);
                    }
                    else
                    {
                        sql = "update  zdy_inter_table set dupdatetime=getdate() FROM dbo.zdy_inter_table where clx='存货档案' ";
                        DbHelper2.ExecuteNonQuery(sql,_cconstr);


                    }
                    return cError;
                }


                return "推送失败";

            }
            catch (Exception ex)
            {
               
                return ex.Message;
            }

        }
        #endregion

        public string PostCus()
        {
            try
            {
                string url = string.Format("{0}/publicInterface.do?token={1}&type={2}&features={3}", _url, _token, "erp", "baseCust");
                //LogHelper.WriteLog(url);
                //url = "http://demo.startdream.vip/info/openInter/publicInterface.do?token=yonyou&type=erp&features=baseCust";
                var client = new RestClient(url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                IRestResponse response = client.Execute(request);
                //结果返回类
                //JsonConvert,将jason转换成类，返回成功，更新u8已上传状态
                FanHuiDatailCus obj = JsonConvert.DeserializeObject<FanHuiDatailCus>(response.Content);
                if (obj.success.ToLower() == "true")
                {
                    //写到数据表
                    //先清空再插入，然后更新存货档案
                    List<Customer> lst = obj.list;
                    string sql = "truncate table zdy_lvju_customer ";
                    DbHelper2.ExecuteNonQuery(sql,_cconstr);
                    sql = "truncate table zdy_lvju_customeradd ";
                    DbHelper2.ExecuteNonQuery(sql, _cconstr);
                    for (int i = 0; i < lst.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@cust_code",lst[i].cust_code),
                 new SqlParameter("@cust_forshort",lst[i].cust_forshort),
                   new SqlParameter("@cust_inv_address",lst[i].cust_inv_address),
                    new SqlParameter("@cust_name",lst[i].cust_name)
          };
                        sql = @"INSERT INTO  [zdy_lvju_customer]
           (cust_code
           ,cust_forshort
           ,cust_inv_address,cust_name) values(@cust_code
           ,@cust_forshort
           ,@cust_inv_address,@cust_name)";
                        DbHelper2.ExecuteNonQuery(sql, param,_cconstr);

                        List<Addresss> lstadd = obj.list[i].addresss;
                        for (int j = 0; j < lstadd.Count; j++)
                        {
                            SqlParameter[] paramadd = new SqlParameter[]{
                new SqlParameter("@cust_code",lst[i].cust_code),
                 new SqlParameter("@address",lstadd[j].address)
          };

                            sql = @"INSERT INTO  [zdy_lvju_customeradd]
           (cust_code
           ,addresss) values(@cust_code
           ,@address) select @@identity ";
                            DbHelper2.ExecuteNonQuery(sql, paramadd,_cconstr);
                        }
                    }
                    //执行存储，更新分类、计量单位
                    SqlParameter[] param2 = new SqlParameter[]{
                new SqlParameter("@error",SqlDbType.VarChar,1000) };
                    param2[0].Direction = ParameterDirection.Output;

                    DbHelper2.ExecuteNonQuery("zdy_lvju_sp_ImportCus", param2, CommandType.StoredProcedure,_cconstr);
                    string cError = param2[0].Value.ToString();
                    if (cError != "ok")
                    {
                        Exception ex = new Exception(cError);                        
                    }
                    else
                    {
                        sql = "update  zdy_inter_table set dupdatetime=getdate() FROM dbo.zdy_inter_table where clx='客户档案' ";
                        DbHelper2.ExecuteNonQuery(sql,_cconstr);
                    }
                    return cError;
                }
                return "获取失败";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }

        /// <summary>
        /// 销售参数
        /// </summary>
        public string PostSalePara()
        {
            try
            {
                //string url = string.Format("?token={0}&type={1}&features={2}", "yonyou", "erp", "salesPars");
                string url = string.Format("{0}/publicInterface.do?token={1}&type={2}&features={3}", _url, _token, "erp", "salesPars");
                //LogHelper.WriteLog(url);
                //url = "http://demo.startdream.vip/info/openInter/publicInterface.do?token=yonyou&type=erp&features=baseCust";
                var client = new RestClient(url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                IRestResponse response = client.Execute(request);
                //结果返回类
                //JsonConvert,将jason转换成类，返回成功，更新u8已上传状态
                FanhuiDetailPara obj = JsonConvert.DeserializeObject<FanhuiDetailPara>(response.Content);
                if (obj.success.ToLower() == "true")
                {
                    //写到数据表
                    //先清空再插入，然后更新存货档案
                    List<Reason_code> lst = obj.reason_code;
                    string sql = "delete  from zdy_lvju_SalePara  where clx='Reason_code'";
                    DbHelper2.ExecuteNonQuery(sql,_cconstr);

                    for (int i = 0; i < lst.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@clx","Reason_code"),
                 new SqlParameter("@ccode",lst[i].reason_code),
                 new SqlParameter("@cdesc",lst[i].reason_desc),
                 new SqlParameter("@dprice",lst[i].dc_price)
          };
                        sql = @"INSERT INTO zdy_lvju_SalePara
           (clx,ccode,cdesc,dprice) values(@clx,@ccode,@cdesc,@dprice
          )";
                        DbHelper2.ExecuteNonQuery(sql, param, _cconstr);
                    }

                    List<Sales_type> lst2 = obj.sales_type;
                    sql = "delete  from zdy_lvju_SalePara  where clx='Sales_type'";
                    DbHelper2.ExecuteNonQuery(sql,_cconstr);

                    for (int i = 0; i < lst2.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@clx","Sales_type"),
                 new SqlParameter("@ccode",lst2[i].price_code),
                 new SqlParameter("@cdesc",lst2[i].price_desc),
                 new SqlParameter("@dprice",'0')
          };
                        sql = @"INSERT INTO zdy_lvju_SalePara
           (clx,ccode,cdesc,dprice) values(@clx,@ccode,@cdesc,@dprice
          )";
                        DbHelper2.ExecuteNonQuery(sql, param,_cconstr);
                    }

                    List<Packing_sort> lst3 = obj.packing_sort;
                    sql = "delete  from zdy_lvju_SalePara  where clx='Packing_sort'";
                    DbHelper2.ExecuteNonQuery(sql,_cconstr);

                    for (int i = 0; i < lst3.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@clx","Packing_sort"),
                 new SqlParameter("@ccode",lst3[i].packing_sort),
                 new SqlParameter("@cdesc",lst3[i].packing_desc),
                 new SqlParameter("@dprice",lst3[i].bz_price)
          };
                        sql = @"INSERT INTO zdy_lvju_SalePara
           (clx,ccode,cdesc,dprice) values(@clx,@ccode,@cdesc,@dprice
          )";
                        DbHelper2.ExecuteNonQuery(sql, param,_cconstr);
                    }
                    //执行存储，更新分类、计量单位
                    SqlParameter[] param2 = new SqlParameter[]{
                new SqlParameter("@error",SqlDbType.VarChar,1000) };
                    param2[0].Direction = ParameterDirection.Output;
                    DbHelper2.ExecuteNonQuery("zdy_lvju_sp_ImportSalePara", param2, CommandType.StoredProcedure,_cconstr);
                    string cError = param2[0].Value.ToString();
                    if (cError != "ok")
                    {
                        Exception ex = new Exception(cError);
                    }
                    else
                    {
                        sql = "update  zdy_inter_table set dupdatetime=getdate() FROM dbo.zdy_inter_table where clx='销售参数' ";
                        DbHelper2.ExecuteNonQuery(sql,_cconstr);


                    }
                    return cError;
                }

                return "获取失败";
            }
            catch (Exception ex)
            {
               return ex.Message;
               
            }


        }

        public string PostWarehouse()
        {
            try
            {
                string url = string.Format("{0}?token={1}&type={2}&features={3}", _url, "yonyou", "erp", "baseDepot");
                var client = new RestClient(url);
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                IRestResponse response = client.Execute(request);
                //结果返回类
                //JsonConvert,将jason转换成类，返回成功，更新u8已上传状态
                FanhuiDetailWare obj = JsonConvert.DeserializeObject<FanhuiDetailWare>(response.Content);
                if (obj.success.ToLower() == "true")
                {
                    //写到数据表
                    //先清空再插入，然后更新存货档案
                    List<Warehouse> lst = obj.list;
                    string sql = "truncate table zdy_lvju_warehouse ";
                    DbHelper2.ExecuteNonQuery(sql,_cconstr);

                    for (int i = 0; i < lst.Count; i++)
                    {
                        SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@depot_code",lst[i].DEPOT_CODE),
                 new SqlParameter("@DEPOT_NAME",lst[i].DEPOT_NAME)
          };
                        sql = @"INSERT INTO  [zdy_lvju_warehouse]
           (depot_code
           ,DEPOT_NAME) values(@depot_code
           ,@DEPOT_NAME
          )";
                        DbHelper2.ExecuteNonQuery(sql, param, _cconstr);
                    }


                    //执行存储，更新分类、计量单位
                    SqlParameter[] param2 = new SqlParameter[]{
                new SqlParameter("@error",SqlDbType.VarChar,1000) };
                    param2[0].Direction = ParameterDirection.Output;

                    DbHelper2.ExecuteNonQuery("zdy_lvju_sp_ImportWare", param2, CommandType.StoredProcedure, _cconstr);
                    string cError = param2[0].Value.ToString();
                    if (cError != "ok")
                    {
                        Exception ex = new Exception(cError);

                    }
                    else
                    {
                        sql = "update  zdy_inter_table set dupdatetime=getdate() FROM dbo.zdy_inter_table where clx='客户档案' ";
                        DbHelper2.ExecuteNonQuery(sql, _cconstr);


                    }
                    return cError;
                }
                return "推送失败";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }

        #region  销售推送
        /// <summary>
        /// 推送销售订单
        /// </summary>
        private string  PostSo()
        {
            string cErr = "";
            string sql = @"SELECT id,csocode,ccuscode,cCusOAddress,ddate,cmemo FROM dbo.so_somain WHERE ISNULL(cdefine15, 0) = 0
AND dDate>= '2021-3-16'";
            DataTable dt = DbHelper2.ExecuteTable(sql,_cconstr);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                int iId = DbHelper.GetDbInt(dt.Rows[i]["id"]);


                SoMain soMain = new SoMain();
                soMain.comp_id = "0001";
                soMain.cust_code = DbHelper.GetDbString(dt.Rows[i]["ccuscode"]);
                //soMain.cust_sn ="";
                soMain.cust_address = DbHelper.GetDbString(dt.Rows[i]["cCusOAddress"]);
                soMain.bill_date = DbHelper.GetDbDate(dt.Rows[i]["ddate"]);
                soMain.depot_code = "XC0001";
                soMain.csocode = DbHelper.GetDbString(dt.Rows[i]["csocode"]);
                soMain.remark = DbHelper.GetDbString(dt.Rows[i]["cmemo"]);

                sql = string.Format(@"
SELECT iRowNo,a.isosid, cInvCode,iQuantity,iTaxUnitPrice,B.cAlias AS Sales_type,C.cAlias AS Reason_code,D.cAlias AS Packing_sort,E.cAlias AS Match_Code,F.cAlias AS Color_code,cMemo 
FROM dbo.SO_SODetails A
LEFT JOIN dbo.UserDefine B ON A.cDefine22=B.cValue AND B.cID='22'
LEFT JOIN dbo.UserDefine C ON A.cDefine23=C.cValue AND C.cID='23'
LEFT JOIN dbo.UserDefine D ON A.cDefine24=D.cValue AND D.cID='24'
LEFT JOIN dbo.UserDefine E ON A.cDefine25=E.cValue AND E.cID='25'
LEFT JOIN dbo.UserDefine F ON A.cFree1=F.cValue AND F.cID='20' WHERE ID ={0}", iId);
                DataTable dt2 = DbHelper2.ExecuteTable(sql,_cconstr);
                List<SoDetail> soDetails = new List<SoDetail>();
                for (int j = 0; j < dt2.Rows.Count; j++)
                {
                    SoDetail soDetail = new SoDetail();
                    soDetail.s_n = DbHelper.GetDbInt(dt2.Rows[j]["iRowNo"]);
                    soDetail.isosid = DbHelper.GetDbInt(dt2.Rows[j]["isosid"]);
                    soDetail.mat_code = DbHelper.GetDbString(dt2.Rows[j]["cInvCode"]);
                    soDetail.qty = DbHelper.GetDbInt(dt2.Rows[j]["iQuantity"]);
                    soDetail.color_code = DbHelper.GetDbString(dt2.Rows[j]["Color_code"]);
                    soDetail.unit_price = DbHelper.GetDbdecimal(dt2.Rows[j]["iTaxUnitPrice"]);
                    //soDetail.mc = DbHelper.GetDbString(dt2.Rows[j]["Match_Code"]);
                    //soDetail.ps = DbHelper.GetDbString(dt2.Rows[j]["Packing_sort"]);
                    //soDetail.rc = DbHelper.GetDbString(dt2.Rows[j]["Reason_code"]);
                    //soDetail.st = DbHelper.GetDbString(dt2.Rows[j]["Sales_type"]);
                    soDetail.mc = "PZ00";
                    soDetail.ps = "01";
                    soDetail.rc = "001";
                    soDetail.st = "001";

                    soDetails.Add(soDetail);
                }
                //转换成jason
                string jsonsomain = JsonConvert.SerializeObject(soMain);
                string jsonsodetails = JsonConvert.SerializeObject(soDetails);


                try
                {
                    string url = string.Format("{0}/syncWriteInterface.do?token={1}&type=erp&features=saveSalesOrder&businessType=plOrder", _url, _token );
                    var client = new RestClient(url);
                    client.Timeout = -1;
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                    request.AddParameter("pd_m", jsonsomain);
                    request.AddParameter("pd_d", jsonsodetails);
                    IRestResponse response = client.Execute(request);
                    FanhuiDetailSo obj = JsonConvert.DeserializeObject<FanhuiDetailSo>(response.Content);
                    if (obj.success.ToLower() == "true")
                    {
                        sql = string.Format(@"update so_somain set cdefine15=1,cdefine14='{1}' where id= '{0}'", iId, obj.retu_billno);
                        DbHelper2.ExecuteNonQuery(sql,_cconstr);
                        //MessageBox.Show(soMain.csocode + "：ok");
                    }
                    else
                    {
                        sql = string.Format(@"update so_somain set cdefine14='{1}' where id= '{0}'", iId, obj.msg);
                        DbHelper2.ExecuteNonQuery(sql,_cconstr);
                        //MessageBox.Show(soMain.csocode + "：error,"+ obj.msg);
                    }
                    cErr += soMain.csocode + ":" + obj.success+ obj.msg + "\r\n";


                }
                catch (Exception ex)
                {
                    cErr += soMain.csocode+":"+ ex.Message+ "\r\n";
                    //MessageBox.Show(ex.Message);
                    continue;
                }

            }
            return cErr;
        }
        #endregion
        #region 返回数据类
        public class FanHuiDatailINV
        {
            public string success { get; set; }
            public List<Inventory> list { get; set; }
        }

        public class Inventory
        {
            /// <summary>
            /// 测试TDR123
            /// </summary>
            public string material_type { get; set; }
            /// <summary>
            /// 系统测试专用整车
            /// </summary>
            public string material_spec { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string s_n { get; set; }
            /// <summary>
            /// 辆
            /// </summary>
            public string unit_code { get; set; }
            /// <summary>
            /// 魅力咖啡
            /// </summary>
            public string color_desc { get; set; }
            /// <summary>
            /// 测试整车
            /// </summary>
            public string material_name { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string color_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string material_code { get; set; }
        }


        public class FanHuiDatailCus
        {
            public string success { get; set; }
            public List<Customer> list { get; set; }
        }

        public class Customer
        {
            /// <summary>
            /// 
            /// </summary>
            public string cust_code { get; set; }
            /// <summary>
            /// 备库
            /// </summary>
            public string cust_forshort { get; set; }
            /// <summary>
            /// 备库
            /// </summary>
            public string cust_inv_address { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<Addresss> addresss { get; set; }
            /// <summary>
            /// 备库
            /// </summary>
            public string cust_name { get; set; }
        }
        public class Addresss
        {
            /// <summary>
            /// 
            /// </summary>
            public int s_n { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string address { get; set; }
        }



        public class Warehouse
        {
            /// <summary>
            ///  危险品仓库
            /// </summary>
            public string DEPOT_NAME { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string PAUSE_FLAG { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string COST_SIGN { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string DEPOTCODE_ID { get; set; }
            /// <summary>
            /// 原材料仓库
            /// </summary>
            public string SORT_DESC { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string REQU_PLAN { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string NOTAX_SIGN { get; set; }
            /// <summary>
            /// 无锡公司
            /// </summary>
            public string COMP_ABBR_CN { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string DEPOT_ADDR { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string DEPOT_CODE { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string STOCK_NEGATIVE { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string COMP_ID { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string SHARE_FLAG { get; set; }
            /// <summary>
            /// 梦雪网络科技有限公司（无锡）
            /// </summary>
            public string COMP_CN_NAME { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string bi_counts { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string REMARK { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string DEPOT_SORT { get; set; }
        }

        public class FanhuiDetailWare
        {
            /// <summary>
            /// 
            /// </summary>
            public string success { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<Warehouse> list { get; set; }
        }

        public class FanhuiDetailSo
        {
            /// <summary>
            /// 
            /// </summary>
            public string success { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string msg { get; set; }

            public string retu_billno { get; set; }

            public string ym { get; set; }

            public string recode { get; set; }

        }


        public class FanhuiDetailPara
        {
            /// <summary>
            /// 
            /// </summary>
            public string success { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<Reason_code> reason_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<string> match_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public List<Sales_type> sales_type { get; set; }

            /// <summary>
            /// 
            /// </summary>
            public List<Packing_sort> packing_sort { get; set; }

        }

        public class Reason_code
        {
            /// <summary>
            /// 
            /// </summary>
            public string reason_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public decimal dc_price { get; set; }
            /// <summary>
            /// 空配
            /// </summary>
            public string reason_desc { get; set; }
        }

        public class Sales_type
        {
            /// <summary>
            /// 
            /// </summary>
            public string price_code { get; set; }
            /// <summary>
            /// 正价车
            /// </summary>
            public string price_desc { get; set; }
        }

        public class Packing_sort
        {
            /// <summary>
            /// 散装
            /// </summary>
            public string packing_desc { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public decimal bz_price { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string packing_sort { get; set; }
        }

        public class SoMain
        {
            /// <summary>
            /// 
            /// </summary>
            public string comp_id { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public DateTime bill_date { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string cust_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string cust_sn { get; set; }
            public string cust_address { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string depot_code { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string remark { get; set; }
            public string csocode { get; set; }
        }

        public class SoDetail
        {
            /// <summary>
            /// 
            /// </summary>
            public int s_n { get; set; }

            public int isosid { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string mat_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string color_code { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string st { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string rc { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string ps { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public string mc { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public int qty { get; set; }
            /// <summary>
            /// 
            /// </summary>
            public decimal unit_price { get; set; }
            /// <summary>
            /// 行备注
            /// </summary>
            public string remark { get; set; }
        }

        public class SoOrder
        {
            public SoMain pd_m { get; set; }

            public List<SoDetail> pd_d { get; set; }

        }
        #endregion
    }
}
